// ej6.cpp
#include "myFunctions.h"
#include "Hopfield.h"
int main(int argc,char *argv[]){
	cout<<"Semilla: "<<time(NULL)<<endl;
	srand(time(NULL));
	int numTest = 100;
	float probability = 0.1;
	int numEntradas = 35;
	int numDigits = 7;

	
	vector<int> Xtest;
	vector<vector<int> > DIGITS;
	DIGITS.resize(numDigits);
	for(int i=0;i<numDigits;i++){
		stringstream cvz;
		cvz<<i;
		string snumero = cvz.str();
		string nomArchi = "patterns/"+snumero+".txt";
		readFile(DIGITS[i], nomArchi);
	}	
	
	Hopfield H = Hopfield("config_ej6.txt");
	
	H.training(DIGITS);

	int numErrores = 0;
	int numBitErroneos = 0;

	for(int i=0;i<numTest;i++){
		int d = (int)(uniformDouble()*numDigits);
		cout<<"D: "<<d<<endl;
		vector<int> Xtest = genTest(DIGITS[d],probability);
		vector<int> out = H.output(Xtest);
		int bitErroneos = 0;
		bool error = false;
		for(int j=0;j<numEntradas;j++){
			if(out[j] != DIGITS[d][j]){
				error = true;
				bitErroneos++;
			}
		}

		if(error){
			cout<<endl<<"Salida Erronea! - Bits Erroneos: "<<bitErroneos<<endl;
			numErrores++;
			numBitErroneos += bitErroneos;
		}else{
			cout<<endl<<"Salida Correcta!: "<<endl;
		}
		cout<<endl<<"Entrada Sucia[arriba] -  Salida Obtenida [al medio] - salida deseada [abajo] "<<endl<<endl;
		view_vi(Xtest);
		view_vi(out);
		view_vi(DIGITS[d]);
		cout<<endl<<"----------------------------------------------------------------------------------------"<<endl;
	}

	
	cout<<endl<<"En Total se obtuvieron "<<(numTest-numErrores)<<" salidas correctas de "<<numTest<<endl<<endl;
	cout<<"Un Promedio de "<<(double)numBitErroneos/(double)numTest<<" bit Erroneos por test "<<endl<<endl;

	return 1;
}
